package com.ren.mianshi.http.retrofit;

import java.io.File;
import java.util.List;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * @Description：Retrofit辅助类
 * @Author： ren
 * @Date： 2020-05-02
 */
public class RetrofitHelper {


	/**
	 * 图片上传
	 * @param imageMap key上传图片时的multiPart名字   value需要上传图片的本地路径
	 * @return
	 */
	public List<MultipartBody.Part> createImageParts(Map<String, String> imageMap) {
		MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);

		for (Map.Entry<String, String> m : imageMap.entrySet()) {
			File imageFile = new File(m.getValue());
			MediaType mediaType = MediaType.parse("image/png");
			RequestBody fileBody = RequestBody.create(mediaType, imageFile);
			builder.addFormDataPart(m.getKey(), imageFile.getName(), fileBody);
		}
		List<MultipartBody.Part> parts = builder.build().parts();
		return parts;
	}

}
